<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Design Pattern</title>
    <meta name="language" content="en" />
    <!--myInjectedScript-->
</head>
<body>
    <h1>
        Singleton</h1>
    <div class="section">
        <h2>
            Intent</h2>
        <p>
            Ensure a class only has one instance, and provide a global point of access to it.<br />
        </p>
    </div>
    <div class="section">
        <h2>
            Motivation</h2>
        <p>
            It's important for some classes to have exactly one instance. The class has only
            one instance and that the instance is easily accessible. A global variable makes
            an object accessible, but it doesn't keep you from instantiating multiple objects.<br />
            Hence the class itself responsible for keeping track of its sole instance. The class
            can ensure that no other instance can be created (by intercepting requests to create
            new objects), and it can provide a way to access the instance.
            <br />
            <a href="http://en.wikipedia.org/wiki/Singleton_pattern" target="_blank">Online resources</a>
        </p>
    </div>
    <div class="section">
        <h2>
            Applicability</h2>
        <p>
            <ol>
                <li>there must be exactly one instance of a class, and it must be accessible toclients
                    froma well-known accesspoint. </li>
                <li>when the sole instance should be extensible by subclassing, and clients should be
                    able to use an extended instance without modifying their code.</li>
            </ol>
        </p>
    </div>
    <div class="section">
        <h2>
            Class Diagram</h2>
        <p>
            <img alt="Diagram" src="singleton.png" border="0" />
        </p>
    </div>
    <div class="section">
        <h2>
            Collaborations</h2>
        <p>
            Clients access a Singleton instance solely through Singleton's Instance operation.
        </p>
    </div>
    <div class="section">
        <h2>
            Consequences</h2>
        <p>
            <ol>
                <li>Controlled access to sole instance.Because the Singleton class encapsulates its
                    sole instance, it can have strict control over how and when clients accessit.</li>
                <li>Reduced name space. The Singleton pattern is an improvement over global variables.
                    It avoids polluting the name space with global variables that store sole instances.</li>
                <li>Permits refinement of operations and representation. The Singleton class may be
                    subclassed, and it's easy to configure an application with an instance of this extended
                    class. You can configure the application with an instance ofthe classyou need at
                    run-time.</li>
                <li>Permits a variable number of instances. The pattern makes it easy to change your
                    mind and allow more than one instance of the Singleton class. Moreover, you can
                    use the same approach to control the number of instances that the application uses.
                    Only the operation that grants access to the Singleton instance needs to change.</li>
                <li>More flexible than class/static operations. It is easier to change a design to allow
                    more than one instance of a class or to allow inheritance and override them polymorphically.
                </li>
            </ol>
        </p>
    </div>
    <div class="section">
        <h2>
            Related Patterns</h2>
        <p>
            <ul>
                <li><a href="">Abstract Factory</a></li>
                <li><a href="">Builder</a></li>
                <li><a href="">Prototype</a></li>
            </ul>
        </p>
    </div>
</body>
</html>
